package com.huatai.exchange.bootup.controller;

import com.faneui.bootup.controller.AbstractRestController;
import com.faneui.common.exception.BusinessException;
import com.faneui.common.utils.BeanMapper;
import com.faneui.common.utils.ListUtils;
import com.huatai.exchange.dal.model.ExcExchangeInfo;
import com.huatai.exchange.facade.ExchangeInfoController;
import com.huatai.exchange.facade.bean.ExchangeInfoVo;
import com.huatai.exchange.facade.bean.QueryExchangeInfoVoListResp;
import com.huatai.exchange.service.ExcExchangeInfoService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 *  文件数据交换中心
 *
 */
@RestController
@RequestMapping(value = "exchange")
@Api("数据文件交换配置信息")
public class ExchangeInfoControllerImpl  extends AbstractRestController implements ExchangeInfoController {

    @Autowired
    private ExcExchangeInfoService exchangeInfoService ;

    @RequestMapping(value = "/list", method = RequestMethod.GET)
    @ResponseBody
    public QueryExchangeInfoVoListResp queryExchangeInfoVoList(@ModelAttribute ExchangeInfoVo exchangeInfoVo) throws BusinessException {
        QueryExchangeInfoVoListResp resp = new QueryExchangeInfoVoListResp();
        try {
            ExcExchangeInfo info = BeanMapper.map(exchangeInfoVo,ExcExchangeInfo.class) ;
            List<ExcExchangeInfo> infos = exchangeInfoService.queryExcExchangeInfoList(info) ;
            if(ListUtils.isNotEmpty(infos)) {
                List<ExchangeInfoVo> vos = BeanMapper.mapList(infos,ExchangeInfoVo.class) ;
                resp.setExchangeInfoVos(vos);
            }
        }catch (Exception ex) {
            resp.setSuccess(false);
            resp.setMsg(ex.getMessage());
        }
        return resp;
    }


}
